package com.crystal.jcms.shpz;

import com.crystal.jcms.utils.SpUtils;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Handler;

public class ActivitySplash extends Activity {
	Context mContext;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mContext = this;
		setContentView(R.layout.activity_splash);
		Handler handler = new Handler();
		handler.postDelayed(new Runnable() {
			public void run() {
				Intent intent = new Intent();
				// 1. 首先判断ServerUrl是否为空
				if (SpUtils.get(mContext, "ServerUrl", "").equals("")) {
					intent.setClass(ActivitySplash.this, ActivitySetting.class);
				} else {
					// 2. 判断用户名和密码是否存在，如果存在的话 直接进入main 页面
					String userId = SpUtils.get(mContext, "UserId", "").toString();
					String password = SpUtils.get(mContext, "Password", "").toString();
					if (!userId.equals("") && !password.equals("")) {
						intent.setClass(mContext, ActivityFrame.class);
					} else {
						intent.setClass(ActivitySplash.this, ActivityLogin.class);
					}
				}

				startActivity(intent);
				finish();
			}
		}, 1000);
	}

	@Override
	public void onWindowFocusChanged(boolean hasFocus) {
		super.onWindowFocusChanged(hasFocus);
		Rect outRect = new Rect();
		getWindow().getDecorView().getWindowVisibleDisplayFrame(outRect);
		int iHeight = getWindowManager().getDefaultDisplay().getHeight();
		int iWidth = getWindowManager().getDefaultDisplay().getWidth();
		SpUtils.put(mContext, "AppWidth", outRect.width());
		SpUtils.put(mContext, "AppHeight", outRect.height());
		SpUtils.put(mContext, "ScreenWidth", iWidth);
		SpUtils.put(mContext, "ScreenHeight", iHeight);
	}
}
